package br.com.agiledev.webscrum.eao;

import java.util.Date;
import java.util.List;

import javax.persistence.NoResultException;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import br.com.agiledev.webscrum.entity.DailyScrum;
import br.com.agiledev.webscrum.entity.Release;
import br.com.agiledev.webscrum.entity.Sprint;

@Name("dailyscrumEAO")
@Scope(ScopeType.APPLICATION)
@AutoCreate
public class DailyscrumEAO extends BaseEAO<DailyScrum> {

    /**
     * Recupera o dailyScrum do dia, associado ao sprint.
     * 
     * @param sprint
     *            sprint associado ao dailyScrum.
     * @param data
     *            data do dia do dailyScrum.
     * @return dailyScrum se houver.
     */
    public DailyScrum dailyScrumDoDia(Sprint sprint, Date data) {

	try {
	    return (DailyScrum) getEntityManager().createNamedQuery("DailyScrum.porSprintData").setParameter("sprint",
		    sprint).setParameter("dataReuniao", data).getSingleResult();
	} catch (NoResultException e) {
	    return null;
	}
    }
    
    /**
     * Recupera a lista de dailyScrum do sprint ordenado por data da reuniao.
     * 
     * @param sprint sprint que tera os dailyScrum recuperados.
     * @return lista ordenada pela data de reuniao.
     */
    @SuppressWarnings("unchecked")
    public List<DailyScrum> porSprint(Sprint sprint) {
	return getEntityManager().createNamedQuery("DailyScrum.porSprint").setParameter("sprint", sprint)
		.getResultList();
    }

    /**
     * Recupera a lista de dailyScrum da release ordenado por data da reuniao.
     * 
     * @param release release que tera os dailyScrum recuperados.
     * @return lista ordenada pela data de reuniao.
     */
    @SuppressWarnings("unchecked")
    public List<DailyScrum> porRelease(Release release) {
	return getEntityManager().createNamedQuery("DailyScrum.porRelease").setParameter("release", release)
		.getResultList();
    }
}